package com.atguigu03.threadsafe.threadsafe;

/**
 * ClassName: Windows7
 * Package: com.atguigu03.threadsafe.threadsafe
 * Description:
 *
 * @Author BuTang
 * @Create 2023/5/15 10:57
 * @Version 1.0
 */

public class Windows7 {
    public static void main(String[] args) {
        Windows8 a = new Windows8();
        Windows8 b = new Windows8();
        Windows8 c = new Windows8();
        a.setName("窗口一");
        b.setName("窗口二");
        c.setName("窗口三");

        a.start();
        b.start();
        c.start();
    }
}

class Windows8 extends Thread {
    static int ticket = 100;
    @Override
    public void run() {
        while (ticket >0){
            synchronized (Windows8.class){
                show();}

        }

    }

    public void show() {

        if (ticket > 0) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + "-" + "售票成功：" + ticket);
            ticket--;
        }


    }
}
